package com.pan.concurrency.thread;

import java.util.UUID;

/**
 * <p>
 *      join 方法使调用该方法的线程在此之前执行完毕，
 *      也就是等待调用该方法的线程执行 完毕后再往下继续执行。
 *      注意该方法也要捕获异常。
 * </p>
 *
 * @author kaiji
 * @since 2020/1/14 16:48
 */
public class JoinThread {

    public static void main(String[] args) {
        System.out.println(UUID.randomUUID().toString().replaceAll("-", ""));

        MyJoinRunner myJoinRunner = new MyJoinRunner();
        Thread t = new Thread(myJoinRunner, "子线程");
        t.setPriority(Thread.MAX_PRIORITY);
        t.start();
        try {
            t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "运行完成！");
    }
}

class MyJoinRunner extends Thread {

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
        System.out.println(Thread.currentThread().getName() + "运行完成！");
    }
}
